package georah.carto
{

	import georah.carto.geometries.OGCPoint;
	import georah.carto.geometries.OGCPointZ;

	/**
	 *
	 * @author yuanm
	 */
	public final class PanZoom extends GISCamera
	{
		public function PanZoom(srid:int=4326, x:Number=0.0, y:Number=0.0, z:Number=0.0)
		{
			if (!_where)
			{
				_where=new OGCPointZ();
			}
			_where.SRID=srid;
			_where.x=x;
			_where.y=y;
			_where.z=z;
		}

		public final function calcBBox(width:Number, height:Number):Extent
		{
			var ext:Extent=new Extent();
			ext.minX=where.x - 0.5 * width * where.z;
			ext.maxX=where.x + 0.5 * width * where.z;
			ext.minY=where.y - 0.5 * height * where.z;
			ext.maxY=where.y + 0.5 * height * where.z;
			return ext;
		}

		public final function get center():OGCPoint
		{
			return new OGCPoint(where.SRID, where.x, where.y);
		}

		public final function set center(value:OGCPoint):void
		{
			if (!_where)
			{
				_where=new OGCPointZ();
			}
			_where.SRID=value.SRID;
			_where.x=value.x;
			_where.y=value.y;
		}

		public final function clone():PanZoom
		{
			return new PanZoom(where.SRID, where.x, where.y, where.z);
		}

		public final function pan(dx_:Number, dy_:Number):void
		{
			var c:OGCPointZ=where;
			c.x-=dx_;
			c.y-=dy_;
			_where=c;
		}

		public final function get scale():Number
		{
			return where.z;
		}

		public final function set scale(value:Number):void
		{
			_where.z=value;
		}
		
		public final function zoom(scale_:Number):void
		{
			var c:OGCPointZ=where;
			c.z=where.z * scale_;
			_where=c;
		}
		
	}
}
